package org.zhxy.zhxy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zhxy.zhxy.interceptor.LoginInterceptor;
import org.zhxy.zhxy.interceptor.ReFreshInterceptor;

import javax.annotation.Resource;

/**
 * 配置拦截器
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private ReFreshInterceptor reFreshInterceptor;
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {


        //登录拦截器
        registry.addInterceptor(loginInterceptor)
                .excludePathPatterns(
                        //拦截时放行一些路径
                        "/api/user/register",
                        "/api/user/login",
                        "/api/admin/login/**",
                        "/api/email/send",
                        "/api/wx/login",
                        "/api/user/forget-password"
                ).order(1);

        //token刷新拦截器，拦截所有请求，先执行
        registry.addInterceptor(reFreshInterceptor).addPathPatterns("/**").order(0);
    }
}





















